
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-04-19
 * Time: 22:39
 */

public class test {
    static int k;
    static int x, y;
    static int[][] boards =new int[1025][1025];
    static int tile;

    static {
        tile = 1;
    }

    public static void main(String[] args) {
        k = 3;
        x = 1;
        y = 2;
        int size = 1 << k;
        chessBoard(0, 0, x, y, size);
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < size; j++) {
                System.out.print(boards[i][j]+"  ");
            }
            System.out.println();
        }
    }

    static void chessBoard(int tr, int tc, int dr, int dc, int size) {
        if (size == 1) return;
        int t = tile++;
        int s = size / 2;
        //考虑左上角象限
        if (dr < tr + s && dc < tc + s) {
            chessBoard(tr, tc, dr, dc, s);
        } else {
            boards[tr + s - 1][tc + s - 1] = t;
            chessBoard(tr, tc, tr + s - 1, tc + s - 1, s);
        }
        if (dr < tr + s && dc >= tc + s) {
            chessBoard(tr, tc + s, dr, dc, s);
        } else {
            boards[tr + s - 1][tc + s] = t;
            chessBoard(tr, tc + s, tr + s - 1, tc + s, s);
        }
        if (dr >= tr + s && dc < tc + s) {
            chessBoard(tr + s, tc, dr, dc, s);
        } else {
            boards[tr + s][tc + s - 1] = t;
            chessBoard(tr + s, tc, tr + s, tc + s - 1, s);
        }
        if (dr >= tr + s && dc >= tc + s) {
            chessBoard(tr + s, tc + s, dr, dc, s);
        } else {
            boards[tr + s][tc + s] = t;
            chessBoard(tr + s, tc + s, tr + s, tc + s, s);
        }
    }
}
